﻿using System;
using System.Drawing;
using RRRSRoguelike.Entities.Props;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Managers;
using RRRSRoguelikeData;

namespace RRRSRoguelike.Entities.Creatures
{
	/// <summary>
	/// Player inherits from creature.
	/// </summary>
	public class Player : Creature
	{
		#region variables
		//easier calls
		private GameManager gameManager = GameManager.Instance;
		//super basic inventory - very game specific should be more dynamic
		private Weapon weaponSlot;
		//Yay an event, more of these please!!!
		
		
		public event RaiseStatHandler WeaponChanged;
		public event RaiseStatHandler PlayerMoved;
		
		//Keeps a list of stats associated with the player.  Again should be more dynamic.  
		//I would prefer and interface.
		public Stats Stats;
		
		
		#endregion
		#region constructor
		/// <summary>
		/// Initializes player
		/// </summary>
		/// <param name="p"></param>
		public Player(Point position, TileData tileData)
			: base(position, tileData)
		{
		}
		#endregion
		#region properties
		
		//The following methods are very specific to the vanilla game.  
		//Thinking about a slot class that is plugable into the creature class.
		public void AddWeapon(Weapon weapon)
		{
			weaponSlot = weapon;
			if (WeaponChanged != null)
				WeaponChanged(this, new RaiseStatArgs("WeaponsGrabbed",1));
		}

		public void RemoveWeapon()
		{
			weaponSlot = null;
			if (WeaponChanged != null)
				WeaponChanged(this, new RaiseStatArgs("WeaponsGrabbed",0));
		}

		public bool HasWeapon()
		{
			return weaponSlot != null;
		}

		public void UseWeapon()
		{
			weaponSlot.Use(this);
		}

		public Weapon WeaponSlot
		{
			get { return weaponSlot; }
		}

		#endregion
		#region methods
		// This should be two separate methods.  Add one to the tile.
		public Boolean MovePlayer(Direction direction, int distance = 1)
		{
			//check for valid move
			for (int i = distance; i > 0; i--)
			{
				Point newPosition = DungeonLevel.GetNewPosition(Position, direction, i);
				if (gameManager.DungeonLevel.IsOKToMove(newPosition))
				{
					Position = newPosition;
					if (PlayerMoved != null)
						PlayerMoved(this, new RaiseStatArgs("StepsTaken",1));
					
					//early out!!!
					return true;
				}
			}
			return false;
		}


		#endregion
	}
}
